<template>
  <div>

    <table border="1" width="700" style="border-collapse: collapse">
      <caption>
        购物车
      </caption>
      <thead>
          <div >
          <tr>
          <th><input type="checkbox" v-model="isAll" /> <span>全选</span></th>
          <th>名称</th>
          <th>价格</th>
          <th>数量</th>
          <th>总价</th>
          <th>操作</th>
        </tr>
      </div>
      </thead>
      <tbody>
        <Min 
      :obj="goodList"
        @isAll=isAll
        @delClick=delFn
        />
      </tbody>
      <tfoot>
        <Footom 
       :arr="goodList"
         />
      </tfoot>
    </table>
  </div>
</template>

<script>
// 1.创建组件
import Min from "./components/ToGou.vue/Mnie.vue"
import Footom from "./components/ToGou.vue/Footom.vue"
export default {
// 2.注册组件
  components:{
Min,
Footom
  },
  data() {
    return {
      goodList: [
        {
          name: "诸葛亮",
          price: 1000,
          num: 1,
          checked: false,
        },
        {
          name: "蔡文姬",
          price: 1500,
          num: 1,
          checked: false,
        },
        {
          name: "妲己",
          price: 2000,
          num: 1,
          checked: false,
        },
        {
          name: "鲁班",
          price: 2200,
          num: 1,
          checked: false,
        },
      ],
    };
  },
  // 计算属性
  computed: {
    isAll:{
      // set 重置的意思 把大选框的值赋值给每一项的小选框
      set(val){
        this.goodList.forEach(item=>item.checked=val)
      },
      // get 获取 把小选框的每一项的选中状态返给 全选框
      get(){
        return this.goodList.every(item=>item.checked)
      }
    }
  },
  methods:{
    delFn(index){
      this.goodList.splice(index,1)
    }

  }
  

};
</script>

<style scoped>


th{
border:1px solid #ccc;
width: 700px;

}
</style>
